package com.tuliyou.controller;

import com.tuliyou.common.util.Result;
import com.tuliyou.dto.PageInfo;
import com.tuliyou.dto.UserFavoriteDTO;
import com.tuliyou.request.UserFavoriteRequest;
import com.tuliyou.service.UserFavoriteService;
import com.tuliyou.vo.UserFavoriteVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/user-favorites")
public class UserFavoriteController {

    @Resource
    private UserFavoriteService userFavoriteService;

    @PostMapping
    public Result<UserFavoriteDTO> addFavorite(@RequestBody UserFavoriteRequest request){
        log.info("用户收藏");
        return userFavoriteService.addFavorite(request);
    }

    @GetMapping
    public Result<PageInfo<UserFavoriteVO>> getFavorites(
            @RequestParam(defaultValue = "1",required = false) Integer page,
            @RequestParam(defaultValue = "10",required = false) Integer size,
            @RequestParam(defaultValue = "UNIVERSITY") String favoriteType){
        return userFavoriteService.getFavorites(page, size, favoriteType);
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteFavorite(@PathVariable Long id){
        return userFavoriteService.deleteFavorite(id);
    }

}
